package activity.Left;


import android.util.Log;

import java.io.File;

//数据处理的model
public class LeftGetDataModel {
    private static LeftGetDataModel instance = null;
    private static Object mLock = new Object();

    private LeftGetDataModel() {
    }

    public static LeftGetDataModel getInstance() {
        if (instance == null) {
            synchronized (mLock) {
                instance = new LeftGetDataModel();
            }
        }
        return instance;
    }

    /**
     * 获取照片的数量
     *
     * @param path
     * @return
     */
    public int getPhotoNum(String path) {
        String str_download = path + "/Snapshot/";
        File file1 = new File(str_download);
        if (file1 != null && file1.exists()) {
            return file1.listFiles().length;
        }
        return 0;
    }

    /**
     * 获取视屏的数量
     *
     * @param path
     * @return
     */
    public int getVoideNum(String path) {
        String str_download = path + "/Download/";
        File file1 = new File(str_download);
        Log.i("tedu", "--file1--:" + file1.getAbsolutePath() + "--11--:" + file1.exists() + "--22--:" + file1.isDirectory());
        if (file1.exists() && file1.isDirectory()) {
            for (int i = 0; i < file1.listFiles().length; i++) {
                File file11 = file1.listFiles()[i];
                if (file11 != null && file11.exists() && file11.isFile() && file11.length() <= 1024) {
                    file11.delete();
                    continue;
                }
            }
        }
        int a = 0;
        if (file1 != null && file1.exists()) {
            a = file1.listFiles().length;
        }
        String str_videoRecod = path + "/VideoRecoding/";
        File file2 = new File(str_videoRecod);
        Log.i("tedu", "--file2--:" + file2.getAbsolutePath() + "--11--:" + file2.exists() + "--22--:" + file2.isDirectory());
        if (file2.exists() && file2.isDirectory()) {
            for (int i = 0; i < file2.listFiles().length; i++) {
                File file = file2.listFiles()[i];
                if (file != null && file.exists() && file.isFile() && file.length() <= 1024) {
                    file.delete();
                    continue;
                }
            }
        }
        int b = 0;
        if (file2 != null && file2.exists()) {
            b = file2.listFiles().length;
            for (File file : file2.listFiles()) {
                if (file.getName().equals("SnapShot")) {
                    b--;
                }
            }
        }
        return a + b;
    }
}